FROM alpine:3.20

ENV PHPIZE_DEPS="autoconf dpkg-dev dpkg file tar zip g++ gcc libstdc++ libc-dev make pkgconf re2c pcre-dev pcre2-dev zlib-dev libtool automake"

COPY ./run.sh /run.sh

RUN set -ex \
    && sed -i 's/dl-cdn.alpinelinux.org/mirrors.aliyun.com/g' /etc/apk/repositories \
    && apk update \
  	&& apk add --no-cache \
    --virtual .build-deps $PHPIZE_DEPS \
    openssl \
    curl \
    bash \
    ca-certificates \
    libaio-dev \
    openssl-dev \
    curl-dev \
    #openrc \
    #tini \
    tzdata \
    # 安装php
    php83 \
    php83-pear \
    php83-dev \
    php83-mysqli \
    php83-pdo_mysql \
    php83-pdo_sqlite \
    php83-mbstring \
    php83-json \
    php83-zlib \
    php83-gd \
    php83-intl \
    php83-session \
    php83-fpm \
    php83-curl \
    php83-posix \
    php83-fileinfo \
    php83-simplexml \
    php83-opcache  \
    php83-sodium \
    php83-tokenizer \
    php83-ctype \
    php83-bcmath \
    php83-openssl \
    php83-dom \ 
    php83-iconv \
    php83-sockets \
    php83-zip \
    php83-pcntl \
    php83-xmlwriter \
    php83-xmlreader \
    php83-redis \
    php83-xml \
    php83-phar \
    php83-pecl-event \
    && cp "/usr/share/zoneinfo/Asia/Shanghai" /etc/localtime \
    && echo "Asia/Shanghai" > /etc/timezone \
    && update-ca-certificates \
    #添加 www用户组和用户
    && addgroup -g 1000 www \
    && adduser -u 1000 -D -S -G www www \
    && mkdir /www  \
    && chown www:www /www \
    && chmod 1777 /www \
    #&& sed 's/user = nobody/user = www/g' /etc/php83/php-fpm.d/www.conf | sed 's/group = nobody/group = www/g'| sed 's/127.0.0.1/0.0.0.0/g' | sed 's/pm.max_children = 5/pm.max_children = 30/g' | sed 's/pm = dynamic/pm = static/g' > /tmp/www.conf \
    #&& mv /tmp/www.conf /etc/php83/php-fpm.d/www.conf \
    #&& sed 's/;opcache.enable=1/opcache.enable=1/g' /etc/php83/php.ini | sed 's/;opcache.validate_timestamps=1/opcache.validate_timestamps=0/g' | sed 's/;opcache.memory_consumption=128/opcache.memory_consumption=128/g' | sed 's/;opcache.interned_strings_buffer=8/opcache.interned_strings_buffer=8/g' | sed 's/;opcache.max_accelerated_files=10000/opcache.max_accelerated_files=10000/g' > /tmp/php.ini \
    #&& mv /tmp/php.ini /etc/php83/php.ini \
    && apk add gnu-libiconv gnu-libiconv-dev libstdc++ --no-cache --repository http://mirrors.aliyun.com/alpine/edge/community/ --allow-untrusted \
    && ln -s /usr/sbin/php-fpm83 /usr/sbin/php-fpm \
    && ln -s /usr/bin/php83 /usr/bin/php \
    && ln -s /usr/bin/phar83 /usr/bin/phar \
    && ln -s /usr/bin/php-config83 /usr/bin/php-config \
    && ln -s /usr/bin/phpize83 /usr/bin/phpize \
    && chmod +x /run.sh \
    && wget https://mirrors.tencent.com/composer/composer.phar \
    && mv composer.phar  /usr/local/bin/composer \
    && chmod 755 /usr/local/bin/composer \

     # ---------- clear works ----------
    #&& apk del .build-deps \
    #&& rm -rf /var/cache/apk/* /tmp/* /usr/share/man /usr/local/bin/php* 
    && composer config -g repos.packagist composer https://mirrors.tencent.com/composer/

ENV LD_PRELOAD /usr/lib/preloadable_libiconv.so


WORKDIR /www

EXPOSE 8787 9000

#ENTRYPOINT ["/sbin/tini", "-g", "--"]
CMD ["/run.sh"]